function HTMLEncode ( input )
{
var converter = document.createElement("DIV");
converter.innerText = input;
var output = converter.innerHTML;
converter = null;
return output;
}
$(document).ready(function() {
            namespace = '/';
            var socket = io.connect(location.protocol + '//' + document.domain + ':' + location.port + namespace);
//            var socket = io.connect(location.protocol + '//' + '127.0.0.1' + ':' + location.port + namespace);
            socket.on('connect', function(msg){
                socket.emit('join admin', {username:'admin',token:'admin888'});
            });

            socket.on('notice', function(data){
                $("#log").append("<b>notice:"+data.data+"</b>.<br/>");
                $('#log').scrollTop(10000000);
            });
            $('#ctrlc').click(function(){
                socket.emit('exec command', {key:$('#host_key').val(),command:'Ctrl+C'});
            });
            socket.on('exec result', function(data){
                 $("#log").append("<b>"+HTMLEncode(data.result)+"</b><br/>");
                 $('#log').scrollTop(10000000);
            });

            $('form#emit').submit(function(event) {
                    $('#log').append($('#host_key').val() + ":" + $('#command').val() +"<br/>");
                    $('#log').scrollTop(10000000);
                    socket.emit('exec command', {key:$('#host_key').val(),command:$('#command').val()});
                    $('#command').val('');
                return false;
            });

            socket.on('my response', function(msg) {
            console.log(msg);
            });

        });